package com.captjack.micro.api.article;

import com.captjack.micro.api.constant.Constant;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author Capt Jack
 * @date 2018/4/17
 */
@FeignClient(name = Constant.ARTICLE_MICRO_SERVICE_NAME, fallbackFactory = MicroServiceTwo.FallbackMicroServiceTwo.class)
@RequestMapping(value = "microServiceTwo", method = {RequestMethod.GET, RequestMethod.POST})
public interface MicroServiceTwo {

    String SERVICE_URL = "http://" + Constant.ARTICLE_MICRO_SERVICE_NAME + "/microServiceTwo/message";

    /**
     * 测试
     *
     * @return String
     * @throws Exception 异常
     */
    @RequestMapping("/message")
    String service() throws Exception;

    /**
     * fallback实现
     */
    @Component
    final class FallbackMicroServiceTwo implements FallbackFactory<MicroServiceTwo> {

        @Override
        public MicroServiceTwo create(Throwable throwable) {
            return () -> {
                throwable.printStackTrace();
                return Constant.DEFAULT_HYSTRIX_MESSAGE;
            };
        }

    }

}
